package com.edu.exam.entity.assessment;

import com.edu.exam.enums.TemplateType;
import com.edu.exam.enums.TemplateStatus;
import com.edu.exam.enums.questionbank.QuestionDifficultyLevel;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 考核方案模板实体类
 * 所属模块：B-04 考核方案管理模块
 * 对应数据库表：assessment_plan_template
 *
 * 根据B-04考核方案管理模块设计文档实现
 * 管理可复用的考核方案模板，包括模板基本信息、结构配置、适用范围等。
 *
 * @author System
 * @version 1.0.0
 */

@Entity
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
public class AssessmentPlanTemplate {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 模板编码，系统唯一标识
     */
    @Column(name = "code", nullable = false, length = 50, unique = true)
    private String code;

    /**
     * 模板名称
     */
    @Column(name = "name", nullable = false, length = 200)
    private String name;

    /**
     * 模板描述
     */
    @Column(name = "description", columnDefinition = "TEXT")
    private String description;

    /**
     * 模板类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "type", nullable = false, length = 20)
    private TemplateType type;

    /**
     * 模板状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false, length = 20)
    private TemplateStatus status;

    /**
     * 适用课程类型
     */
    @Column(name = "applicable_course_types", length = 500)
    private String applicableCourseTypes;

    /**
     * 适用培养层次
     */
    @Column(name = "applicable_education_levels", length = 200)
    private String applicableEducationLevels;

    /**
     * 适用学分范围
     */
    @Column(name = "applicable_credit_range", length = 100)
    private String applicableCreditRange;

    /**
     * 模板结构（JSON格式存储项目配置）
     */
    @Column(name = "template_structure", columnDefinition = "TEXT")
    private String templateStructure;

    /**
     * 默认总分
     */
    @Column(name = "default_total_score", precision = 8, scale = 2)
    private BigDecimal defaultTotalScore;

    /**
     * 默认及格分
     */
    @Column(name = "default_passing_score", precision = 8, scale = 2)
    private BigDecimal defaultPassingScore;

    /**
     * 默认优秀分
     */
    @Column(name = "default_excellent_score", precision = 8, scale = 2)
    private BigDecimal defaultExcellentScore;

    /**
     * 推荐项目配置
     */
    @Column(name = "recommended_items", columnDefinition = "TEXT")
    private String recommendedItems;

    /**
     * 推荐标准配置
     */
    @Column(name = "recommended_standards", columnDefinition = "TEXT")
    private String recommendedStandards;

    /**
     * 使用说明
     */
    @Column(name = "usage_instructions", columnDefinition = "TEXT")
    private String usageInstructions;

    /**
     * 模板标签
     */
    @Column(name = "tags", length = 500)
    private String tags;

    /**
     * 难度等级
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "difficulty_level", length = 20)
    private QuestionDifficultyLevel difficultyLevel;

    /**
     * 创建者ID
     */
    @Column(name = "creator_id", nullable = false)
    private Long creatorId;

    /**
     * 创建者姓名
     */
    @Column(name = "creator_name", nullable = false, length = 100)
    private String creatorName;

    /**
     * 审核者ID
     */
    @Column(name = "reviewer_id")
    private Long reviewerId;

    /**
     * 审核者姓名
     */
    @Column(name = "reviewer_name", length = 100)
    private String reviewerName;

    /**
     * 审核时间
     */
    @Column(name = "review_time")
    private LocalDateTime reviewTime;

    /**
     * 审核意见
     */
    @Column(name = "review_comments", columnDefinition = "TEXT")
    private String reviewComments;

    /**
     * 使用次数
     */
    @Column(name = "usage_count")
    @Builder.Default
    private Integer usageCount = 0;

    /**
     * 最后使用时间
     */
    @Column(name = "last_used_time")
    private LocalDateTime lastUsedTime;

    /**
     * 最后使用者ID
     */
    @Column(name = "last_used_by")
    private Long lastUsedBy;

    /**
     * 版本号
     */
    @Column(name = "version_number", length = 20)
    private String versionNumber;

    /**
     * 创建时间
     */
    @Column(name = "create_time", nullable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @Column(name = "update_time")
    private LocalDateTime updateTime;

    /**
     * 版本号（用于乐观锁）
     */
    @Version
    @Column(name = "version", nullable = false)
    private Long version;

    /**
     * 是否删除
     */
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted = false;

    /**
     * 删除时间
     */
    @Column(name = "deleted_time")
    private LocalDateTime deletedTime;

    /**
     * 删除者ID
     */
    @Column(name = "deleter_id")
    private Long deleterId;

    // 业务方法

}